package com.jizhangben.bean;

import com.jizhangben.pojo.AccountPojo;

import java.util.List;

public class AccountListBean {

    private List<AccountPojo> accounts; // 所有账目
    private int currentPage; // 当前页数
    private int totalPage; // 总页数
    private int pageSize; // 每页显示数量

    public void setAccounts(List<AccountPojo> accounts) {
        this.accounts = accounts;
    }

    public void setCurrentPage(int currentPage) {
        this.currentPage = currentPage;
    }

    public void setTotalPage(List<AccountPojo> accounts) {
        this.totalPage = (int) Math.ceil((double) accounts.size() / pageSize);
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    public List<AccountPojo> getAccounts() {
        return accounts;
    }

    // 构造函数
    public AccountListBean(List<AccountPojo> accounts, int currentPage, int pageSize) {
        this.accounts = accounts;
        this.currentPage = currentPage;
        this.pageSize = pageSize;
        this.totalPage = (int) Math.ceil((double) accounts.size() / pageSize);
    }

    public AccountListBean() {
    }

    // 获取当前页的账目列表
    public List<AccountPojo> getCurrentPageAccounts() {
        int startIndex = (currentPage - 1) * pageSize;
        int endIndex = Math.min(startIndex + pageSize, accounts.size());
        return accounts.subList(startIndex, endIndex);
    }

    // 获取当前页数
    public int getCurrentPage() {
        return currentPage;
    }

    // 获取总页数
    public int getTotalPage() {
        return totalPage;
    }

    // 是否存在上一页
    public boolean getHasPreviousPage() {
        return currentPage > 1;
    }

    // 是否存在下一页
    public boolean getHasNextPage() {
        return currentPage < totalPage;
    }

    // 获取上一页页码
    public int getPreviousPage() {
        return currentPage - 1;
    }

    // 获取下一页页码
    public int getNextPage() {
        return currentPage + 1;
    }

    // 获取每页显示数量
    public int getPageSize() {
        return pageSize;
    }
}
